import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'logic.dart';
import "package:honeypotflutter/public/views/public_appBar.dart";
import 'package:webview_flutter/webview_flutter.dart';

class HLWebViewPage extends StatefulWidget {
  final String url;
  final String? title;
  const HLWebViewPage({
    Key? key,
    required this.url,
    this.title,
  }) : super(key: key);

  @override
  State<HLWebViewPage> createState() => _HLWebViewPageState();
}

class _HLWebViewPageState extends State<HLWebViewPage> {
  final HLWebViewLogic logic = Get.put(HLWebViewLogic());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    logic.initWebViewController(widget.url);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: HLAppBar(
        navigationTitle: widget.title,
        showBottomLine: true,
        backAction: logic.getBack,
      ),
      body: Column(
        children: [
          Obx(() => (logic.progressValue.value != 1)
              ? LinearProgressIndicator(
                  value: logic.progressValue.value, // 进度值，0.5表示50%
                  backgroundColor: Colors.grey[200], // 进度条的背景颜色
                  valueColor: AlwaysStoppedAnimation(Colors.blue), // 进度条的颜色
                )
              : Container()),
          Expanded(child: WebViewWidget(controller: logic.controller)),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<HLWebViewLogic>();
    super.dispose();
  }
}
